package com.pda.smallbug.myapplication;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.pda.smallbug.myapplication.httpDomain.MainHttp;
import com.pda.smallbug.myapplication.httpDomain.NextHttp;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/6/27.
 */

public class NextAdapter extends RecyclerView.Adapter{
    private  DecimalFormat fnum;
    private  NextActivity context;
    private List<NextHttp.NextData> data=new ArrayList<>();

    public NextAdapter(NextActivity context){
        this.context=context;
        fnum  =   new DecimalFormat("##0.00");
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
       View view= context.getLayoutInflater().inflate(R.layout.next_item,parent,false);
        MyViewHolder holder=new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder1, final int position) {
        MyViewHolder holder= (MyViewHolder) holder1;
        holder.text1.setText(data.get(position).getFNumber());
        holder.text2.setText(data.get(position).getFName());
        holder.text3.setText(data.get(position).getFModel());
        holder.text4.setText(data.get(position).getFBatchNo());
        holder.text5.setText(data.get(position).getFCD());
        holder.text6.setText(String.valueOf(fnum.format(data.get(position).getFTQty())));
        holder.text7.setText(String.valueOf(fnum.format(data.get(position).getFDqty())));
        holder.text11.setText(String.valueOf(fnum.format(data.get(position).getfJds())));
        holder.text8.setText(String.valueOf(fnum.format(data.get(position).getFJqty())));
        holder.text9.setText(data.get(position).getFP());
     //   holder.text10.setText(String.valueOf(data.get(position).getFRatio()));
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void update(List<NextHttp.NextData> data) {
        this.data=data;
        notifyDataSetChanged();
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{

        private final TextView text1,text2,text3,text4,text5,text6,text7,text8,text9,text11;

        public MyViewHolder(View itemView) {
            super(itemView);
            text1=(TextView)itemView.findViewById(R.id.text1);
            text2=(TextView)itemView.findViewById(R.id.text2);
            text3=(TextView)itemView.findViewById(R.id.text3);
            text4=(TextView)itemView.findViewById(R.id.text4);
            text5=(TextView)itemView.findViewById(R.id.text5);
            text6=(TextView)itemView.findViewById(R.id.text6);
            text7=(TextView)itemView.findViewById(R.id.text7);
            text8=(TextView)itemView.findViewById(R.id.text8);
            text9=(TextView)itemView.findViewById(R.id.text9);
          //  text10=(TextView)itemView.findViewById(R.id.text10);
            text11=(TextView)itemView.findViewById(R.id.text11);
        }
    }
}
